package com.example.util;

import java.util.Scanner;

/**
 * @author 小岁
 * @version 2023/10/31 14:33
 */
public class SalaryUtils {

    //计算个人所得税，按照2022年最新个人所得税税率表计算
    public static float geren(float money) {
        float one = 0, two = 0, three = 0, four = 0, five = 0, six = 0;
        one = (8000 - 5000) * 0.03f;//第一档满额缴费
        two = (17000 - 8000) * 0.1f;//第二档满额缴费
        three = (30000 - 17000) * 0.2f;//第三档满额缴费
        four = (40000 - 30000) * 0.25f;//第四档满额缴费
        five = (60000 - 40000) * 0.3f;//第五档满额缴费
        six = (85000 - 60000) * 0.35f;//第六档满额缴费
        float tax = 0;
        if (money <= 5000)
            tax = 0;//级别1税率
        else if (money <= 8000)
            tax = (money - 5000) * 0.03f;//级别2税率
        else if (money <= 17000)
            tax = (money - 8000) * 0.1f + one;//级别3税率
        else if (money <= 30000)
            tax = (money - 17000) * 0.2f + two + one;//级别4税率
        else if (money <= 40000)
            tax = (money - 30000) * 0.25f + three + two + one;//级别5税率
        else if (money <= 60000)
            tax = (money - 40000) * 0.3f + four + three + two + one;//级别6税率
        else if (money <= 85000)
            tax = (money - 60000) * 0.35f + five + four + three + two + one;//级别7税率
        else
            tax = (money - 85000) * 0.45f + six + five + four + three + two + one;//级别8税率
        return tax;
    }
    public static void main(String[] args) {
        System.out.println("按工资标准缴纳相应的税费：");
        Scanner in = new Scanner(System.in);
        float money =0, old = 0, medicare = 0, outWork = 0, house = 0, total = 0;
        System.out.print("请输入应发工资：");
        money = in.nextFloat();
        old = (float) (money * 0.08);// 计算养老保险,税率为8%
        medicare = (float) (money * 0.02);// 计算医保保险，税率为2%
        outWork = (float) (money * 0.002);// 计算失业保险，税率为0.2%
        house = money * 0.12f;// 计算住房公积金，税率为12%
        total = old + medicare + outWork + house;
        money = money - total;
        float gerenTax = geren(money);
        float income = money - gerenTax;
        System.out.println("养老保险：" + old + "元");
        System.out.println("医疗保险：" + medicare + "元");
        System.out.println("失业保险：" + outWork + "元");
        System.out.println("住房公积金：" + house + "元");
        System.out.println("应缴纳保险总额：" + total + "元");
        System.out.println("应交个人所得税：" + gerenTax + "元");
        System.out.println("税后实际收入为：" + income + "元");
    }
}